{include file="news/header.tpl"}
<link rel="stylesheet"
	href="/static/public/ztree/css/zTreeStyle/zTreeStyle.css"
	type="text/css">




<!-- 头部// -->
{include file="news/top.tpl"} {include file="news/nav.tpl"}
<!-- start: Content -->
<div id="content" class="span10">


<div class="row-fluid">


<div class="well"><!-- Default panel contents -->



<div class="box-content">{$lang['PREMISSION']}:<span id="authorize"></span>
{$lang['SPECPAGE']}:<span id="index_temp"></span> {$lang['LISTPAGE']}:<span
	id="list_temp"></span> {$lang['CONTENTPAGE']}:<span id="content_temp"></span>

<table class="table">
	<form action="#" method="post">
	<tr>
		<td class="span4"><input type="hidden" name="category"
			value="{$category.id}"> <input id="citySel" type="text" name="cate"
			readonly value="{$category.name}{$category.id}" style="width: 120px;"
			onclick="showMenu(); return false;" />

		<div id="menuContent" class="menuContent"
			style="position: absolute; max-height: 500px; overflow-y: scroll">
		<ul id="treeDemo" class="ztree"
			style="margin-top: 0; background-color: #FFF; border: 1px solid #f0f0f0"></ul>
		</div>
		</td>
<td class="span7">
		<a href="#" id="zilei" target="_blank">子类静态</a>|<a href="#"
			id="fenlei" target="_blank">本类静态</a>|<a href="#" id="add"
			target="_blank">内容静态</a>|<a href="#" id="view" target="_blank">查看内容</a>|<a
			id="temp" href="" target="_blank">动态预览</a> |<a id="static" href="#"
			target="_blank">静态预览</a></td>

	</tr>
	
	<tr>
	<td></td>
		<td>
		<div class="form-inline">
<span class="label">新增</span>
			<select name="module" id="module" class="input-small">
			<option value=1 selected>文章</option>
			<option value=2>图片</option>

			<option value=3>专题</option>
			<option value=4>商品</option>
			<option value=5>分类</option>

			<option value=8>系统</option>

		</select> 
		<input type=text name=name id="catename"> 
		<div class="btn-group">
		
	<input type="hidden" class="category" name="category"
			id="category" value=""> <input type="button" name="add"
			value="{$lang['SAVE']}" class="btn btn-primary"
			onclick="return addCate(this)"></input> <input type="button"
			name="del" value="{$lang['DEL']}" class="btn btn-primary"
			onclick="return addCate(this)"></input> <input type="button"
			name="rename" value="{$lang['UPDATE']}" class="btn btn-primary"
			onclick="return addCate(this)"></div> </div></td>
	</tr>
	
	</form>
	



	<tr>
	<td></td>
		<td>	<div class="form-inline">
		<span class="label">模板</span>
		
		<select name="type" id="type" class="input-small">
			<option value="temp_index">专题</option>
			<option value="temp_list" selected>列表</option>
			<option value="temp_content">内容</option>
		</select>
		
			<input type="text" name="temp_name" />
		


		<input type="hidden" name="category" class="category" value="">
		<input type="button" name="bind" value="{$lang['BIND']}"
			onclick="bind('bind')" class="btn btn-primary">
	</div>	</td>
		
	</tr>
	

	


	<tr>

		<td></td>
		<td>
		<div class="form-inline">
				<span class="label">授权</span>
		
		 <select name="groupid" id="groupid" class="input-small">
			<option value=1>超级管理员</option>
			<option value=2>管理员</option>
			<option value=3>验证用户</option>
			<option value=4>注册用户</option>
			<option value=5 selected>任何人</option>
		</select>   <input type="checkbox" name="jicheng" value="1">{$lang['FORWARD']}(默认:任何人)
		<input type="button" name="add" value="{$lang['AUTHORIZE']}"
			onclick="shouquan()" class="btn btn-primary"></div>
		</td>
	</tr>



</table>
</div>
</div>
</div>

<script type="text/javascript" src="/static/public/jquery.js"></script>
<script type="text/javascript"
	src="/static/public/ztree/jquery.ztree.core-3.3.js"></script>
<script type="text/javascript"
	src="/static/public/ztree/jquery.ztree.excheck-3.3.js"></script>

<script type="text/javascript"
	src="/static/public/ztree/jquery.ztree.exedit-3.3.js"></script>

{literal}
<SCRIPT LANGUAGE="JavaScript">
   var zTreeObj;
   // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
   var setting = {
		   async: {
				enable: true,
				url:"/cate/ztree",
				dataType: "json",
				autoParam:["id"],
				otherParam:{"otherParam":"zTreeAsyncTest"},
			},
		   data:{
simpleData:{
enable:true,
idKey:"id",
pIdKey:"pid",
rootPId:null	
}
		   },
		   edit: {
				enable: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
		   callback: {
				onClick: onClick,
				onDblClick:cc,
				beforeDrag: beforeDrag,
				beforeDrop: beforeDrop
			}
		   };
   // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）

   $(document).ready(function(){
      zTreeObj = $.fn.zTree.init($("#treeDemo"), setting);
	      $("button").bind('click',addCate);
		  	setCheck();
			$("#copy").bind("change", setCheck);
			$("#move").bind("change", setCheck);
			$("#prev").bind("change", setCheck);
			$("#inner").bind("change", setCheck);
			$("#next").bind("change", setCheck);
		showMenu();
   });
function showMenu() {
	var cityObj = $("#citySel");
	var cityOffset = $("#citySel").offset();
	$("#menuContent").slideDown("fast");

	$("body").bind("mousedown", onBodyDown);
}
function hideMenu() {
	$("#menuContent").fadeOut("fast");
	//$("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
	if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
		//hideMenu();
	}
}
function beforeDrag(treeId, treeNodes) {
	for (var i=0,l=treeNodes.length; i<l; i++) {
		if (treeNodes[i].drag === false) {
			return false;
		}
	}
	return true;
}
function beforeDrop(treeId, treeNodes, targetNode, moveType) {
    var currentid=$("input[name='category']").val();
	$.post("/news/move",{fid:targetNode.id,id:currentid},function(data){
   alert(data.message);
		},"json")
	return targetNode ? targetNode.drop !== false : true;
}
function setCheck() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	isCopy = $("#copy").attr("checked"),
	isMove = $("#move").attr("checked"),
	prev = $("#prev").attr("checked"),
	inner = $("#inner").attr("checked"),
	next = $("#next").attr("checked");
	zTree.setting.edit.drag.isCopy = isCopy;
	zTree.setting.edit.drag.isMove = true;

	zTree.setting.edit.drag.prev = prev;
	zTree.setting.edit.drag.inner = inner;
	zTree.setting.edit.drag.next = next;
}



 function cc(event, treeId, treeNode, clickFlag){
    var cid=treeNode.id;
    window.location.href='/factory/data/?mid=1&cid='+cid;
setTimeOut(2000);
    }
	function onClick(event, treeId, treeNode, clickFlag) {
		
	  $(".category").val(treeNode.id);
		$.post("/cate/category",{cid:treeNode.id},function(data){
			json=data.message;
			$("#parent").html("parent:"+json.name);
			$("#cate_name").html(json.name);
			$("#index_temp").html('<a href="/temp/edittemp/?name='+json.temp_index+'"  target="_blank">'+json.temp_index+'</a>');
			$("#list_temp").html('<a href="/temp/edittemp/?name='+json.temp_list+'"  target="_blank">'+json.temp_list+'</a>');
			$("#content_temp").html('<a href="/temp/edittemp/?name='+json.temp_content+'"  target="_blank">'+json.temp_content+'</a>');
			$("#authorize").html(json.groupname);
			$("#zilei").attr('href','/news/batch/?mod=c&s=all&cid='+treeNode.id);
			$("#fenlei").attr('href','/news/batch/?mod=c&s=none&cid='+treeNode.id);
			
			$("#add").attr('href','/news/batch/?mod=v&cid='+treeNode.id);
			$("#view").attr('href','/factory/c/?mid=1&cid='+treeNode.id);
			$("#temp").attr('href','/news/c/?cid='+treeNode.id);
			$("#static").attr('href','/a/c/'+treeNode.id+'.html');
			
			},"json");
			ccl();
			 
		Nodes=treeNode;
		
	}		
	function ccl(){
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	nodes = zTree.getSelectedNodes(),
	v = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		v += nodes[i].name + ",";
	}
	if (v.length > 0 ) v = v.substring(0, v.length-1);
	var cityObj = $("#citySel");

	var id=v.match(/\d+/g);
	$("input[name='category']").val(id);
	cityObj.attr("value", v);
	//hideMenu();
	}
var Nodes;
	function addCate(obj,treeNode){
		var type=obj.name;
		var name=$("#catename").val();
		var category=$("#category").val();
		var module=$("#module").val();
       if(category.length>13){
     alert("分类字数太多，请删减无法提交");
     return false;
        }
		
       $.post("/cate/editcategory",{type:type,name:name,mid:module,category:category},function(json){
        alert(json.message);
        if(type=='add'){
        	  zTreeObj.addNodes(Nodes, {id:json.data.id,pid:category, name:name});
          	  }
  	  
          	  if(type=='del'){
          		  zTreeObj.removeNode(Nodes);
           	     
          	 }
        
	  },"json");
  	  

	};
function bind(types){

var name=$("input[name='temp_name']").val();
var t=$("#type").val();
var categoryid=$("#category").val();
	$.post("/cate/bind",{name:name,type:t,model:types,category:categoryid},function(json){

if(json.status==true){
alert(json.message);
	
}
		},"json");
}
function shouquan(){

  var 	id=$("input[name='category']").val();
  var g=$("#groupid").val();
  var k=$("input[name='jicheng']").attr("checked");

  $.post("/cate/savecate",{id:id,groupid:g,jicheng:k},function(json){
    alert(json.message);
  },"json");
}

  </SCRIPT>

{/literal}
 {include file="news/footer.tpl"}
